<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                template="template.xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
    </h:head>
    <body id="body" >


        <ui:define id="side" name="side">

            <h:form id="allCreditForm"  >

                <p:dataTable  var="credit" value="#{creditView.allCredits}" >
                    <p:column headerText="Options">
                        <p:commandButton value="edit" action="#{creditView.editCredit(credit.id)}" ajax="false" />
                        <p:commandButton value="delete" action="#{creditView.deleteCredit(credit.id)}" ajax="false" />
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Id"/>
                        </f:facet>
                        <div class="#{credit.used}">
                        <h:outputText class="#{credit.used}" value="#{credit.id}"/>
                        </div>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="File name" />
                        </f:facet>
                        <div class="#{credit.used}">
                        <h:outputText value="#{credit.fileName}"/>
                        </div>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Is Used?" />
                        </f:facet>
                        <div class="#{credit.used}">
                            <h:outputText value="#{credit.used}"/>
                        </div>
                    </p:column>
                    <p:column>
                        <f:facet name="header">
                            <h:outputText value="Company" />
                        </f:facet>
                        <div class="#{credit.used}">
                            <h:outputText value="#{credit.companyDenomination.company.name}"/>
                        </div>
                    </p:column>
                    <p:column>
                        <p:button outcome="singleCredit" value="Show">
                            <f:param name="id" value="#{credit.id}" />
                        </p:button>
                    </p:column>

                </p:dataTable>
            </h:form>

        </ui:define>
        <ui:define id="content"  name="content">

            <h:form id="creditForm">
                New Credit
                <p:panelGrid columns="2">
                    <p:outputLabel for="pin" value="Pin Code " />
                    <p:inputText required="true" id="pin" value="#{creditAction.credit.pin}" />
                    <p:outputLabel value="Select Voucher" />
                    <p:selectOneMenu value="#{creditAction.companyDenominationID}" >
                        <f:selectItems value="#{companyDenominationView.allCompanyDenominations}" var="compDenom"
                                       itemLabel="#{compDenom.company.name}-#{compDenom.denomination.currency} #{compDenom.denomination.amount.toString()}" itemValue="#{compDenom.id}" />
                    </p:selectOneMenu>
                    <p:commandButton update="@form :tabview:allCreditForm" value="Save" action="#{creditAction.save()}" ajax="false"/>

                </p:panelGrid>
            </h:form>
        </ui:define>
    </body>
</ui:composition>